import React, { Component } from 'react';
import './App.css';

import AppHead from './page/head/AppHead';
import AppFoot from './page/foot/AppFoot';



class App extends Component {

    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            index:sessionStorage.index===undefined?0:Number.parseInt(sessionStorage.index)
        };
    }

    render() {
        return (
            <div className="App" >
                <AppHead index={this.state.index} />
                {this.props.children}
                <AppFoot />
            </div>
        );
    }

    componentWillReceiveProps() {
        if (sessionStorage.index === undefined) return;
        let index = sessionStorage.index===undefined?0:Number.parseInt(sessionStorage.index);
        window.scrollTo(0,0);
        if (this.state.index !== index) {
            this.setState({
                index:index
            })
        }
    }

}

export default App;
